package com.ashokvarma.bottomnavigation.utils

import android.util.Log
import java.util.concurrent.TimeUnit


/**
 * @Title：
 * @Description：
 * @Author：xuefeng.zhu
 * @Since：2023/12/26
 * @Version：1.0.0
 */
object TimeUtils {

    /**
     * 格式化时间为 天 时分秒为->天：：：：
     */
    fun millis2FitTimeSpan(targetMillis: Long): String? {
        if (targetMillis < 0) return ""
        val sb = StringBuilder()
        try {
            var dayMillisUnit = 86400000
            var hoursMillisUnit = 3600000
            var secondMillisUnit = 60000

            var day = TimeUnit.MILLISECONDS.toDays(targetMillis)
//
//            if (day > 0) {
//                sb.append(day.toString() + "天内")
//                return sb.toString()
//            }

            var hours = TimeUnit.MILLISECONDS.toHours(targetMillis - day * dayMillisUnit)
            var hoursStr = if (hours < 10) "0${hours}" else hours
            sb.append("${hoursStr}:")

            var minutes = TimeUnit.MILLISECONDS.toMinutes(targetMillis - day * dayMillisUnit - hours * hoursMillisUnit)
            var minutesStr = if (minutes < 10) "0${minutes}" else minutes
            sb.append("${minutesStr}:")

            var seconds = TimeUnit.MILLISECONDS.toSeconds(targetMillis - day * dayMillisUnit - hours * hoursMillisUnit - minutes * secondMillisUnit)
            var secondsStr = if (seconds < 10) "0${seconds}" else seconds
            sb.append(secondsStr)
        } catch (e: Exception) {
            Log.e("bottom_nvg", e.toString())
        }
        return sb.toString()
    }

    /**
     *
     * 当前时间是否小于七天
     */
    fun isLessThanSeven(targetMillis: Long): Boolean? {
        if (targetMillis <= 0) return false
        var dayMillisUnit = 86400 * 7
        return targetMillis <= dayMillisUnit
    }
}